<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .orange {
            width: 200px;
            height: 40px;
            border: none;
            background-color: orange;
        }
    </style>
</head>

<body>
    <div class="root">
        <input type="text" placeholder="用户名/邮箱/手机号" v-model="username">
        <span v-show="flag" @click="delVal">X</span>
        <br>

        <input type="password" placeholder="请输入密码"><br>
        <button :disabled=dis @click="submit" class="orange">登录</button>
        {{username.length}}
    </div>
    <script src="./vue.js"></script>
    <script>
        //阻止vue在启动时生成生产提示
        Vue.config.productionTip = false;
        //创建vue实例
        const vm = new Vue({
            el: '.root',
            data: function () {
                return {
                    username: '',
                    flag: false,
                    dis:true,
                }
            }, methods: {
                delVal() {
                    this.username = '';
                },
                submit(){
                    console.log('submit');
                }
            },
            watch: {
                username: {
                    handler(value) {
                        console.log(value.length);
                        if (value.length >= 0) {
                            this.flag = true;
                        }
                        if (value.length == 11) {
                            this.flag = false;
                            this.dis=false;
                        }else{
                            this.dis = true;
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>